<?php

namespace App\Model;


use Illuminate\Http\Request;

class RoomReco extends BaseModel
{
    protected $table = 'room_reco';
    private $fields = ['id','room_id','type'];
    protected $fillable = ['room_id','type'];
    public $timestamps = false;

    public function getList(Request $request){
        return curl_request(getKkaudioApiUrl() . '/inner/room/reco/get', [], 'json', 'GET');
//        $limit = $request->input('limit',10);
//        $page = $request->input('page',1);
//        $type = $request->input('type',-1);
//        $room_uid = trim($request->input('room_uid',''));
//
//        $query = new self();
//
//        $query = $query->whereHas('room',function ($query) use($room_uid){
//            $query->select(['room_id']);
//            if($room_uid) $query->where('room_uid','like',"{$room_uid}%");
//        });
//        if($type >= 0) $query = $query->where('type', $type);
//        return $query->with(['room:room_id,name,room_uid'])
//            ->orderBy('id','desc')->paginate($limit,$this->fields,'page',$page);
    }

    public function createData($data){
//        return self::create($request->only(['room_id','type']));
        return curl_request(getKkaudioApiUrl() . '/inner/room/reco/create', $data, 'urlencoded', 'GET');
    }

    public function updateData($data){
        return curl_request(getKkaudioApiUrl() . '/inner/room/reco/update', $data, 'urlencoded', 'GET');
//        return self::where('id',$id)
//            ->update($request->only(['room_id','type']));
    }

    public function deleteData($data){
        return curl_request(getKkaudioApiUrl() . '/inner/room/reco/remove', $data, 'urlencoded', 'GET');

//        return self::destroy($id);
    }

    public function room(){
        return $this->belongsTo(Room::class,'room_id','room_id');
    }
}
